package face.pay.web.com.cenenter.safe.controller;
import face.pay.system.annotation.CurrentUser;
import face.pay.entity.UserInfo;
import face.pay.util.ResultMessage;
import face.pay.web.com.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


@Controller
@RequestMapping(value="/user_center/account")
public class ChangePasswordController {

    @Autowired
    private IUserService iUserService;

    @RequestMapping(value = "/to_pass_modify")
    public String page(@CurrentUser UserInfo loginUser, Model model){

        //判断当前用户是否登录
        if(null==loginUser){
            return "login";
        }
        loginUser.setDeleted(0);
        UserInfo userdata=iUserService.queryUserInfo(loginUser);
        model.addAttribute("userInfo",userdata);
        return "com/center/changePassword";
    }

    @RequestMapping(value = "/modify_pwd", method = RequestMethod.POST)
    @ResponseBody
    public ResultMessage passWordModify(String validateCode, String newPassword, @CurrentUser UserInfo loginUser, HttpServletRequest httpServletRequest) {

        return  iUserService.modifyPassword(loginUser, validateCode,  newPassword);
    }

}
